﻿#include <thread> //线程库
#include <core/Simulator.h>
#include <core/CPU.h>
#include <Common.h>
#include <csignal>
#include <utils/ThreadPool.h>

#define TAG "Main"

//清退函数,注意先后顺序
// 清退线程池，如果速度过快导致提交的任务在销毁之后进行就会有问题 std::this_thread::sleep_for(std::chrono::seconds(3)); // 延时1秒
void cleanup()
{
   ThreadPool::getInstance()->exit();
}

void sigint_handler(int sig)
{
    if (sig == SIGINT) {
        Abort("exit by ctrl + C");
    }
}

#ifndef _TEST__

int main(int argc, char* argv[])
{
    int status;
    CPU* cpu;
    int time = 0;

    //todo cmd
    LogD("enter");
    Simulator* ardlator = Simulator::getInstance();
    cpu = ardlator->init();
    signal(SIGINT, sigint_handler);
    while ((status = ardlator->mainLoopShouldExit()) == 0)
    {
        cpu->interruptHandle();
        time += cpu->exec();
    }
    cleanup();
    return status;
}
#endif // !_TEST__